create database greenlife
go
use greenlife
go
create table News
(
	NewsID int identity(1,1) not null,
	Title nvarchar(100) not null,--luu tieu de noi dung
	QuickTitle nvarchar(150),-- luu noi dung trich dan cua ban tin
	Images varchar(max),--luu hinh anh
	Contents nvarchar(max) not null,-- luu noi dung ban tin
	NewsDate datetime default getDate(),
	NStatus int default 1, -- 1 tin tuc, 2 tien do du an, 3 thong bao tu GreenLife
	constraint PK_News primary key (NewsID)
)
go
create table GreenLifes
(
	GreenLifesID int identity(1,1) not null,
	GreenLifesTitle nvarchar(100) not null,--luu tieu de noi dung
	GreenLifesQuickTitle nvarchar(150),-- luu noi dung trich dan cua ban tin
	GreenLifesImages varchar(max),--luu hinh anh
	GreenLifesContents nvarchar(max) not null,-- luu noi dung ban tin
	GreenLifesStatus int default 1, -- 1 vitri, 2 tong quan, 3 tien ich, 4 chu dau tu
	constraint PK_GreenLifes primary key (GreenLifesID)
)
go
create table Users
(
	UserName varchar(50) not null,
	Passwords varchar(40) not null,
	UsersStatus int,
	constraint PK_Users primary key (UserName)
)
go
create table Category
(
	CategoryID int identity(1,1) not null,
	CategoryName nvarchar(50) not null,
	CategoryType nvarchar(20) default('Tower A'),--co 2 loai Tower A va Tower B
	CategoryDescription nvarchar(250),
	constraint PK_Category primary key (CategoryID)
)
go
create table SubCategory
(
	SubCategoryID int identity(1,1) not null,
	CategoryID int not null,
	SubCategoryName nvarchar(50) not null,
	SubCategoryImage varchar(max),
	SubCategoryDescription nvarchar(max),
	SubCategoryArea float,
	SubCategoryHuong nvarchar(50),
	constraint PK_SubCategory primary key (SubCategoryID),
	constraint FK_SubCategory_CategoryID foreign key (CategoryID) references Category(CategoryID)
)
go
create table GarellyCategory
(
	GarellyCategoryID int identity(1,1) not null,
	SubCategoryID int,
	GarellyImage varchar(max),
	constraint PK_GarellyCategory primary key (GarellyCategoryID),
	constraint FK_SubCategory_SubCategoryID foreign key (SubCategoryID) references SubCategory(SubCategoryID)
)
go
create table Customer
(
	CustomerID int identity(1,1) not null,
	CustomerName nvarchar(50) not null,
	CustomerPhone nvarchar(15),
	CustomerEmail nvarchar(150) not null,
	constraint PK_Customer primary key (CustomerID)
)
go
create table Orders
(
	OrdersID int identity(1,1) not null,
	CustomerID int not null,
	SubCategoryID int not null,
	CreateDate datetime,
	constraint PK_Orders primary key (OrdersID),
	constraint FK_Orders_CategoryID foreign key (CustomerID) references Customer(CustomerID),
	constraint FK_Orders_SubCategoryID foreign key (SubCategoryID) references SubCategory(SubCategoryID)
)
go
create table Feedback
(
	FeedbackID int identity(1,1) not null,
	CustomerID int not null,
	Contents nvarchar(max) not null,
	FeedbackType nvarchar(100),
	FeedbackStatus int, -- 0 chua doc, 1 doc roi, 2 tra loi roi
	constraint PK_Feedback primary key (FeedbackID),
	constraint FK_Feedback_CustomerID foreign key (CustomerID) references Customer(CustomerID)
)
go
create table LinkWeb
(
	LinkWebID int identity(1,1) not null,
	LinkWebName nvarchar(100) not null,
	LinkWebSite nvarchar(100) not null,
	constraint PK_LinkWeb primary key (LinkWebID)
)

